package com.li.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.li.entity.Book;
import com.li.mapper.BookMapper;
import com.li.utils.RedisUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookService {

    @Resource
    BookMapper bookMapper;

    @Resource
    RedisUtil redisUtil;

    @Cacheable("book")
    public PageInfo<Book> bookList() {
        PageHelper.startPage(1,20);
        List<Book> bookList = bookMapper.selectAll();
        redisUtil.setex("bookList", bookList, 300000);
        PageInfo<Book> pageInfo = new PageInfo<>(bookList);
        return pageInfo;
    }
}
